#include "levelmanager.h"
#include "iomanager.h"
#include "level.h"
#include <QDebug>

LevelManager::LevelManager() :
    ioManager(new IOManager("levels.db"))
{
    ioManager->loadLevels(levels);
}

Level *LevelManager::getLevel(qint32 id)
{
    QLinkedList<Level*>::const_iterator it;
    for (it=levels.begin(); it!=levels.end(); it++)
    {
        qDebug() << (*it)->getId();
        if ( (*it)->getId() == id )
            return (*it);
    }
    return NULL;
}

void LevelManager::saveLevel(Level *level)
{
    if (level==NULL)
        return;

    if (level->getId()==-1)
    {
        level->setId(levels.size()+1);
        levels.append(level);
    }
    ioManager->saveLevels(levels);
}
